import { ChangeDetectorRef, Component, Input, OnInit, ViewChild } from '@angular/core';
import { SFComponent, SFSchema, SFUISchema } from '@delon/form';
import { ApiService } from '@core/services/api';
import { HttpClient } from '@angular/common/http';
import { NzMessageService, NzModalRef } from 'ng-zorro-antd';
import { UtilService } from '@core/services/util.service';

@Component({
  selector: 'app-qrcode-batch-add',
  templateUrl: './qrcode-batch-add.component.html',
  styles: []
})
export class QrcodeBatchAddComponent implements OnInit {
  @ViewChild('sf', { static: false }) sf!: SFComponent;
  @Input()type: 0 | 1;
  @Input()
  set _param(value) {
    if (!value) return;
    this.param = value;
    console.log(this.param);
    
  };
  param: any;
  value:any;
  nodes=[];
  timeout:any="";
  show:boolean=true;
  showForm = false;
  isLoading:boolean=false;
  schema: SFSchema = {
    properties: {
      type: {
        type: 'number',
        title: '选择类型',
        enum: [
          {label: '小区', value: 2},
          {label: '出入口', value: 1}
        ],
        ui: {
          widget: 'select',
        }
      },
      // url: {
      //   type: 'string',
      //   title: '链接url',
      // },
      num: {
        type: 'number',
        title: '数量',
        minimum:1,
        maximum:100,
        ui:{
          widget:'number',
          
        }
      },

    },
    required: ['type','num']
  }

  formSubmit(data) {
    let urlStr=""
    if(data.type == 1){//出入口
        urlStr = "https://xtxspmj.com/miniprogram/callPersonList"
    }else if(data.type == 2){//小区
        urlStr = "https://xtxspmj.com/miniprogram/callVillagePersonList"
    }
    const body: any = {
      url : urlStr,
      type : data.type,
      num : data.num
    }
    const url = '/core/qrcode/batch/create';
    const method = 'POST';
    this.http.request<any>(method, url,  { body}).subscribe(res => {
      console.log(res)
      if (res.status === '200' || res.status === '201') {
        this.msg.success('操作成功');
        this.modalRef.triggerOk();
      } else {
        this.msg.error(res.message)
      }
    })

  }

  constructor(
    private api: ApiService,
    private http: HttpClient,
    private msg: NzMessageService,
    private modalRef: NzModalRef,
    private util: UtilService,
    private ref: ChangeDetectorRef,
  ) { }

  async ngOnInit() {
    this.showForm = true;
  }

}
